<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="com.sinodata.bsm.center.bean.ResTypeBean"%>
<%@page import="java.util.*"%>
<%@page import="com.sinodata.bsm.common.vo.*"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="org.springframework.jdbc.core.JdbcTemplate"%>
<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <%
  	ResType bean = (ResType)request.getAttribute("resType");
 	JdbcTemplate template =SpringContextHolder.getBean(JdbcTemplate.class);
 	List<Map<String,Object>> list = template.queryForList("select * from monitor_type order by id");
 	Long selectedMonitor=0L;
 	Long selfFlag= 0L;
 	try{
 		Map<String,Object> oldRel= template.queryForMap("select * from moti_restype_rel where RES_TYPE_ID="+bean.getId());
 		selectedMonitor = Long.parseLong(oldRel.get("MOIT_TYPE_ID").toString());
 		if(oldRel.get("self_flag")!=null){
 			selfFlag = Long.parseLong(oldRel.get("self_flag").toString());
 		}
 	
 	}catch(Exception e){
 	    	
 	}
   %>
<html>
  <head>
  	<title>资源模型</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>   
    <%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/table.jsp"%>
	
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/sub_menu.css" />
	
	<script type="text/javascript">
		
		$(document).ready(function(){
			
			var url = window.parent.location.href;
			if(url.indexOf('displayIndex')!=-1){
				$('#viewAll').toggle();
			}
		
			$("#attributeInfo").dataTable({
				"bProcessing": true, 
				"aaData": ${attributes},
				"bSort": true,
				"bPaginate": true,
				"iDisplayLength":10,
				"aLengthMenu": [[10], [10]],
				"sDom":'rt <"bottom"flpi>',
				"bFilter":false,
				"sPaginationType": 'full_numbers',
				"aoColumns":[
					{"mDataProp":"id"},
					{"mDataProp":"name","bSortable": false},
					{"mDataProp":"resTypeName","bSortable": false},
					{"mDataProp":"dataTypeName","bSortable": false},
					{"mDataProp":"dataUnit","bSortable": false},
					{"mDataProp":"desc","bSortable": false},
					{"mDataProp":"dataTypeId","bVisible":false},
					{"mDataProp":"resType","bVisible":false}
				],
				"oLanguage":{
					"sLengthMenu": "每页 _MENU_ 条",
	 		 		"sZeroRecords": "  ",
					"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
					"sInfoEmpty": "没有找到记录",
					"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}
				}
			});
			
			
			$("#propertyInfo").dataTable({
				"bProcessing": true, 
				"aaData": ${propertys},
				"bSort": false,
				"bPaginate": true,
				"iDisplayLength":10,
				"aLengthMenu": [[10], [10]],
				"sDom":'rt <"bottom"flpi>',
				"bFilter":false,
				"sPaginationType": 'full_numbers',
				"aoColumns":[
					{"mDataProp":"id","bSortable": false},
					{"mDataProp":"name","bSortable": false},
					{"mDataProp":"resTypeName","bSortable": false},
					{"mDataProp":"dataTypeName","bSortable": false},
					{"mDataProp":"dataUnit","bSortable": false},
					{"mDataProp":"store","bSortable": false},
					{"mDataProp":"display","asSorting":["asc"],"aTargets":[1]},
					{"mDataProp":"isCollect","bSortable": false},
					{"mDataProp":"dataTypeId","bVisible":false},
					{"mDataProp":"resType","bVisible":false}
					
				],
				"oLanguage":{
					"sLengthMenu": "每页 _MENU_ 条",
	 		 		"sZeroRecords": "  ",
					"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
					"sInfoEmpty": "没有找到记录",
					"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
				}
			});
			
			$('#eventInfo').dataTable({
				"aaData":${eventTypes},
				"bProcessing": true, 
				"bSort": true,
				"bPaginate": true,
				"iDisplayLength":10,
				"aLengthMenu": [[10], [10]],
				"sDom":'rt <"bottom"flpi>',
				"bFilter":false,
				"sScrollX":'100%',
				"sPaginationType": 'full_numbers',
				"aoColumns":[
					{"mDataProp":"id","bSortable": false},
					{"mDataProp":"name","bSortable": false},
					{"mDataProp":"resName","bSortable": false},
					{"mDataProp":"isRecoverable","bSortable": false},
					{"mDataProp":"expr","bSortable": false},
					{"mDataProp":"msg","bSortable": false},
					{"mDataProp":"desc","bSortable": false}
				],
				"oLanguage":{
					"sLengthMenu": "每页 _MENU_ 条",
	 		 		"sZeroRecords": "  ",
					"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
					"sInfoEmpty": "没有找到记录",
					"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}
				}
			});
			
			$("#templates").dataTable({
				"bProcessing": true, 
				"aaData": ${collectTask},
				"bSort": true,
				"bPaginate": true,
				"iDisplayLength":5,
				"aLengthMenu": [[5,10], [5,10]],
				"sDom":'rt <"bottom"flpi>',
				"bFilter":false,
				"sScrollX":'100%',
				"sPaginationType": 'full_numbers',
				"aoColumns":[
					{"mDataProp":"id","bSortable": false},
					{"mDataProp":"resTypeName","bSortable": false},
					{"mDataProp":"collectorId","bSortable": false},
					{"mDataProp":"className","bSortable": false},
					{"mDataProp":"collectParam","bSortable": false},
					{"mDataProp":"collectField","bSortable": false},
					{"mDataProp":"resTypeId","bVisible":false}
				],
				"oLanguage":{
					"sLengthMenu": "每页 _MENU_ 条",
	 		 		"sZeroRecords": "  ",
					"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
					"sInfoEmpty": "没有找到记录",
					"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}
				}
			});
			var selectedMonitor = '<%=selectedMonitor%>';
			$("#selectedMonitor").val(selectedMonitor);
		
			var selfFlag = '<%=selfFlag%>';
			$("#selfFlagSelect").val(selfFlag);
			$('#bt').bind('click', function() {
				selfFlag = $("#selfFlagSelect").val();
				selectedMonitor= $("#monitorSelect").val();
					$.ajax({
					type:'post',
					url:'res-type!saveMonitorType.action',
					global:false,
					async:false,
					cache:false,
					data : "id=${resType.id}&type="+selectedMonitor+"&flag="+selfFlag,
					dataType:'text',
					success:function(data,textStatus){
						alert("保存成功！");
					}
				});
  			
			});
		});
	</script>
	<style type="text/css">
	body{
	background:url(../style/default/datatable/images/title-bg.jpg) repeat-x left top;
	}

*{
	padding:0px;
	margin:0px;
	font-family:“宋体”;
	font-size:12px;
	}
.content{
	width:85%;
	margin:0 auto;
	height:auto;
	width:970px;
	overflow:hidden;
	}
.resource-title{
	font-size:14px;
	height:56px;
	line-height:56px;
	font-weight:bold;
	}
.resource-content{
	height:autopx;
	}
		
/*资源类别基本信息	*/



.list-left{
	width:100%;
	height:atuo;
	list-style:none;
	margin-top:15px;
	}
.list-right{
	width:100%;
	list-style:none;
	margin-top:15px;
}
.list-left li, .list-right li{
	display:block;
	height:auto;
	clear:both;
	height:40px;
	line-height:10px;
	width:98%;
	}	
.service{
	float:left;
	height:40px;
	line-height:40px;
	width:65%;
	text-align:left;

	}
.img-icon{
	width:30%;
	height:40px;
	line-height:40px;
	background:no-repeat;
	text-align:right;
	float:left;
	}
				
.rescat-left{
	width:63%;
	height:206px;
	float:left;
	border:1px solid #dbdbdb;
	}
.rescat-left-title{
	height:186px;
	width:auto;
	border:1px solid #dbdbdb;
	margin-top:10px;
	padding-left:20px;
	}
	
.rescat-h1{
	line-height:18px;
	margin-left:18px;
	color:#000;
	font-weight:bold;
	 }
.rescat-h2{
	color:#000;
	font-weight:bold;
	line-height:18px;
		} 
.rescat-left-border{
	width:1px;
	background:url(images/rescatbg.gif) 0 center repeat-x;
	height:186px;
	}
.Choice{
	width:139px;
	height:20px;
	margin-top:10px;
	}
			
	
/*资源类别关系	*/			
.rescat-right{
	height:206px;
	float:right;
	border:1px solid #dbdbdb;
	padding-left:20px ;
	width:33%;
	}
/*.rescat-right-title{
	width:95%;
	height:186px;
	float:left;
	border:1px solid #dbdbdb;
	}*/	
.view-all{
	width:95%;
	text-align:right;
	height:40px;
	line-height:40px;
	margin-top:2px;
	}	
.list-rel{
	width:95%;
	margin-top:10px;
	
	}	
.list-rel li{
	height:30px;
	list-style:none;
	clear:both;
	line-height:30px;
	text-align:left;
	
	}
.submit-button{
	width:48px;
	height:20px;
	line-height:20px;
	background:url(../style/default/datatable/images/button.gif) no-repeat left top;
	border:0px;
	margin-top:10px;
	padding-left:7px;
	}

.submit-button:hover{
	background:url(../style/default/datatable/images/button-hover.gif) no-repeat left top;
	
	}			
.img-icon-service{
	width:85px;
	height:20px;
	float:left;
	} 	
		
/*属性信息	*/	
.attribute{
	height:22px;
	line-height:22px;
	text-align:left;
	background:url(images/rescatbg.gif) 0 20px repeat-x;
	padding-top:10px;
	margin-bottom:10px;
	clear:both;
	 }
.attribute-in{
	background:#FFF;
	}	 
.border-table {
	border:1px solid #dbdbdb;
	width:100%;
	border-bottom:none;
	 }
.bg-blue{
	background:#e6edf5;
	height:28px;
	}
.sub-border{
	height:29px;
	line-height:29px;
	background:url(images/rescatbg.gif) 0 bottom repeat-x;
	
	}
.sub-border:hover{
	background:#edf2f8;
	}		
.title-h2{
	background:none;
	font-weight:600;
}
.title-h2 img{
    float:none;
    }
.title-h2 span{
   background-image:none;
    }		
.title-h2 span img{
  float:left;
    }	
    
    .column {
	width: 98%;
	height: auto;
	margin: 0px 0px 15px 20px;
	display: block;
	position: relative;
	clear: both;
	float: left;
}	

table.display td {
	white-space: nowrap;
    text-overflow:ellipsis;
    overflow: hidden;
}

</style>
	
  </head>
  
  <body style="border:0px solid red;height:100%;width:98%;">
	
    <div class="resource-title" style="margin-left:20px;text-align:center;width:98%;">资源模型</div>
 	<div class="resource-content column" style="display:block; height:210px; ">
       <fieldset class="rescat-left">
            <legend class="rescat-h1">资源类别基本信息</legend>
            <form   name="resForm" id="resForm" method="post">
            <div style="width:49%; height:100%; display:block; float:left;">
        	<ul class="list-left" id="restable">
            	<li>
                	<span class="img-icon">编号：</span>
                    <span class="service">${resType.id} </span>
                </li>
                <li>
                	<span class="img-icon">名称：</span>
                    <span class="service">${resType.name} </span>
                </li>
                <li>
                	<span class="img-icon">监控类型：</span>
                    <span class="service">
                     
                        			<select id="monitorSelect" name="monitorSelect" class="Choice">
                            <option value="0" <%if(selectedMonitor==0) out.println("selected");%> >-----请选择----</option>
							<%
								for(int i=0; list!=null&&i<list.size(); i++){
								    Map<String,Object> map = list.get(i);
								 	  Long id = Long.parseLong(map.get("ID").toString());
								 	  String name = map.get("NAME").toString();
								 	  out.println("<option value='"+id+"' "+(selectedMonitor==id.longValue() ? "selected": "")+">"+name+"</option>");
								}
							%>
                            </select>
                    </span>
                </li>
                <li>
                	<span class="img-icon">描述：</span>
                    <span class="service">
                       ${resType.desc}
                    </span>
                </li>
            </ul>
            </div>
 <!---end 左边列表-------->
           <div style="width:49%; height:100%; display:block; float:left;">
        	<ul class="list-right">
            	<li>
                	<span class="img-icon">是否自动发现：</span>
                    <span class="service">
                       <c:choose>
							<c:when test="${resFindDef==null}">否</c:when>
							<c:when test="${resFindDef!=null}">是</c:when>
						</c:choose>
                    </span>
                </li>
                <li>
                	<span class="img-icon">自动发现程序：</span>
                    <span class="service">
                        ${className}
                    </span>
                </li>
                <li>
                	<span class="img-icon">是否计算：</span>
                    <span class="service">
                   	<select id="selfFlagSelect" name="selfFlagSelect">
							<option <%if(selfFlag==1) out.println("selected");%> value="1" >是</option>
							<option <%if(selfFlag==0) out.println("selected");%> value="0">否</option>
						</select>
                      <span><input id = "bt" type="button" value="提交" class="submit-button" /></span>
                    </span>
                </li>
            </ul>
            </div> 
                       </form>   
            </fieldset>
 <!------------end 资源类别----------->
       <fieldset class="rescat-right">
            <legend class="rescat-h2">资源类别关系</legend>
        
        	<ul class="list-rel">
            	<li>
                	所属继承关系
                </li>
                <li>
                	<c:forEach items="${parents}" var="p">
					<span><a href="#${p.id}">${p.name}</a> &gt;&gt; </span>
				    </c:forEach>
				     ${resType.name}
                </li>
                <li style="padding-top:15px;">
                	所包含的子类别
                </li>
                <li>
	                <c:forEach items="${childResTypes}" var="r">
					<span><a href="#${r.id}">${r.name}</a></span>
					</c:forEach>
				</li>
            </ul> 
        <div class="view-all" id="viewAll"><a href="res-type!frame.action?id=${resType.id}#displayIndex" target="_blank">查看全部>></a></div>
    </fieldset>
    </div>
  
	
	<div class="column">
	<h2 class="title-h2" onclick="accordionDiv(this)" > <span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span><span>属性信息</span></h2>
		<table width="100%"  id="attributeInfo" cellpadding="0" cellspacing="0" border="0" class="display"  >
			<thead>
    	 		<tr>
    	 			<th width="90px">编号</th>
    	 			<th width="140px">名称</th>
    	 			<th width="60px">资源类别</th>
    	 			<th width="60px">数据类型</th>
    	 			<th width="100px">单位</th>
    	 			<th>描述</th>
    	 		</tr>
    	 	</thead>
		</table>
	</div>
	
	
	<div id="resTypePropertyInfo " class="column" >
		<h2 class="title-h2" onclick="accordionDiv(this)" ><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>指标信息</h2>
	
		<table width="100%"  id="propertyInfo" cellpadding="0" cellspacing="0" border="0" class="display"  >
			<thead>
    	 		<tr>
    	 			<th width="150px">编号</th>
    	 			<th width="150px">名称</th>
    	 			<th width="90px">资源类别</th>
    	 			<th width="90px">数据类型</th>
    	 			<th width="70px">单位</th>
    	 			<th width="70px">存储字段</th>
    	 			<th width="70px">显示序号</th>
    	 			<th width="70px">是否采集</th>
    	 		</tr>
    	 	</thead>
    	 </table>
	</div>
	
	<div id="resTypeEventInfo" class="column">
		<h2 class="title-h2" onclick="accordionDiv(this)" ><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>事件定义</h2>
		<table   id="eventInfo" cellpadding="0" cellspacing="0" border="0" class="display"  >
			<thead>
    	 		<tr>
    	 			<th >编号</th>
    	 			<th >名称</th>
    	 			<th >资源类别</th>
    	 			<th >是否可恢复</th>
    	 			<th >规则表达式</th>
    	 			<th >消息表达式</th>
    	 			<th>描述</th>
    	 		</tr>
    	 	</thead>
    	 </table>
	</div>
	
	<div id="probeTemplate" class="column">
		<h2 class="title-h2" onclick="accordionDiv(this)" ><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>采集模板<hr/></h2>
		<table   id="templates" cellpadding="0" cellspacing="0" border="0" class="display"  >
			<thead>
    	 		<tr>
    	 			<th >编号</th>
    	 			<th>资源类别</th>
    	 			<th >采集程序ID</th>
    	 			<th >采集程序</th>
    	 			<th>采集参数</th>
    	 			<th >指标映射</th>
    	 		</tr>
    	 	</thead>
    	 </table>
	</div>
	
	<div class="column" style="width:100%;height:5px;">
	
	</div>
  </body>
</html>
